package com.zk.atm.utils;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.log4j.Logger;

public class StringUtil {

	public static final Logger logger=Logger.getLogger(StringUtil.class);
	/**
	 * @author zengqun
	 * @remark 判断字符串是否为空，如果为空，则置为空串；不为空，则返回原字符串
	 * @param obj
	 * @return
	 * @throws Exception
	 */
	public static String getPropertyValue(Object obj) throws Exception{
		return obj==null?"":obj.toString();
	}
	
	/**
	 * @author zengqun
	 * @remark 判断str[]{}是否是空集合，如果是，则返回true;否则返回false
	 * @date 2012-9-24
	 * @version 1.0
	 * @param strs
	 * @return
	 * @throws Exception
	 */
	public static boolean isEmptyStringArray(String[] strs) throws Exception{
		return (strs==null||strs.length==0);
	}
	
	/**
	 * @author zengqun
	 * @remark 打印map
	 * @date 2012-9-24
	 * @version 1.0
	 * @param strs
	 * @return
	 * @throws Exception
	 */
	public static void printMap(Map map) throws Exception {
		if (map != null && map.size() > 0) {
			Iterator it = map.entrySet().iterator();
			while (it.hasNext()) {
				Entry e = (Entry) it.next();
				if (logger.isDebugEnabled()) {
					System.out.println("********************StringUtil:printMap:key="+ e.getKey() + ",value=" + e.getValue());
				}
			}
		}
	}
	
	/**
	 * @author zengqun
	 * @remark 打印list
	 * @date 2012-9-26
	 * @param list
	 * @throws Exception
	 */
	public static void printList(List list) throws Exception{
		if(list==null||list.size()==0){
			return;
		}
		for (Object object : list) {
			System.out.println(object);
		}
	}
	
	public static void main(String[] args) {
		try {
			System.out.println(StringUtil.isEmptyStringArray(new String[]{"1"}));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
